﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace CodepageMaintain
{
	partial class AutoCastCollection<T>
	{
		partial class AutoCastEnumerator : IEnumerator<T>
		{
			#region Частные поля класса

			internal IEnumerator _enumerator;

			#endregion

			#region Конструктор

			public AutoCastEnumerator(IEnumerator enumerator)
			{
				_enumerator = enumerator;
			}

			#endregion

			#region IEnumerator<T> Members

			/// <summary>
			/// Gets the element in the collection at the current position of the enumerator.
			/// </summary>
			/// <returns>
			/// The element in the collection at the current position of the enumerator.
			/// </returns>
			public virtual T Current
			{
				get { return (T)this._enumerator.Current; }
			}

			/// <summary>
			/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
			/// </summary>
			/// <filterpriority>2</filterpriority>
			public void Dispose()
			{
				_enumerator = null;
			}

			/// <summary>
			/// Advances the enumerator to the next element of the collection.
			/// </summary>
			/// <returns>
			/// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
			/// </returns>
			/// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception><filterpriority>2</filterpriority>
			public bool MoveNext()
			{
				return _enumerator.MoveNext();
			}

			/// <summary>
			/// Sets the enumerator to its initial position, which is before the first element in the collection.
			/// </summary>
			/// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception><filterpriority>2</filterpriority>
			public void Reset()
			{
				_enumerator.Reset();
			}

			#endregion

			#region IEnumerator Members

			/// <summary>
			/// Gets the current element in the collection.
			/// </summary>
			/// <returns>
			/// The current element in the collection.
			/// </returns>
			/// <exception cref="T:System.InvalidOperationException">The enumerator is positioned before the first element of the collection or after the last element. </exception><filterpriority>2</filterpriority>
			object IEnumerator.Current
			{
				get { return _enumerator.Current; }
			}

			#endregion
		}
	}
}